package demo.helloworld;

import act.Act;
import act.Version;
import act.app.ActionContext;
import act.job.OnAppStart;
import demo.helloworld.service.OptionsService;
import demo.helloworld.util.Const;
import demo.helloworld.util.Tool;
import org.mvel2.util.StringAppender;
import org.osgl.http.H;
import org.osgl.logging.Logger;
import org.osgl.mvc.annotation.GetAction;
import org.rythmengine.Rythm;
import org.rythmengine.RythmEngine;

import javax.inject.Inject;

import java.util.Map;

import static act.controller.Controller.Util.redirect;
import static act.controller.Controller.Util.render;

/**
 * The simple hello world app.
 * <p>Run this app, try to update some of the code, then
 * press F5 in the browser to watch the immediate change
 * in the browser!</p>
 */
@SuppressWarnings("unused")
public class HelloWorldApp {

    @Inject
    OptionsService optionsService;

    @GetAction
    public void home(String who) {
        redirect("/install");
    }

    @GetAction("/install")
    public void install() {
        boolean installed = true;
        render(installed);
    }

    public static void main(String[] args) throws Exception {
        Act.start("Hello World", Version.appVersion(), HelloWorldApp.class);
    }

    @OnAppStart
    public void hello() {
        System.out.println("我是冒牌的监听器:)");
//        for (Map.Entry<String,String> entry : optionsService.getOptions().entrySet()) {
//            System.out.println(entry.getKey() + "-->"+entry.getValue());
//        }
        Map<String, String> options = optionsService.getOptions();
        Const.options = options;
//        for (Map.Entry<String,String> entry : Const.options.entrySet()) {
//            System.out.println(entry.getKey() + "-->"+entry.getValue());
//        }
        String site_title = Const.options.get("site_title");
        //System.out.println(Rythm.render("@args String site_title\nHello @site_title", Const.options));
    }

    private void getValue(String name) {
        for (Map.Entry<String,String> entry : Const.options.entrySet()) {
            if (entry.getKey().contains(name)) {
                System.out.println(entry.getValue());
            }
        }
    }
}
